// import { Component, Vue } from 'vue-property-decorator'
import Component, { mixins } from 'vue-class-component'
import { namespace } from 'vuex-class'

import DialogBoxMixin from '@/mixins/dialog'

import { loading, errorMessage } from '@/utils'

const personalUserModule = namespace('cms/personalUser')
const resumeModule = namespace('cms/resume')
const resumeSendModule = namespace('cms/resumeSend')
const interviewModule = namespace('cms/interview')
const personalLoginRecordModule = namespace('cms/personalUserRecord')

@Component
export default class Index extends mixins(DialogBoxMixin) {
  // 用户
  @personalUserModule.Action('show') personalUserShow!: (payload: any) => Promise<any>

  // 简历
  @resumeModule.Action('show') resumeShow!: (payload: any) => Promise<any>

  // 发送简历投递
  @resumeSendModule.Action getPersonalUserSend!: (payload: any) => Promise<any>
  @resumeSendModule.Action getPersonalResumeSend!: (payload: any) => Promise<any>

  // 收到面试
  @interviewModule.Action getPersonalUserReceiveInterview!: (payload: any) => Promise<any>
  @interviewModule.Action getPersonalResumeReceiveInterview!: (payload: any) => Promise<any>

  // 个人登录记录
  @personalLoginRecordModule.Action userLoginRecord!: (payload: any) => Promise<any>

  /**
   * 对话框：查看个人用户
   *
   * @param {Number} uid
   * @param {Number} [index]
   * @return {void}
   */
  public dialogPersonalUserShow(uid: number, index: number = -1): void {
    const _loading = loading({background: 'transparent'})
    this.personalUserShow({uid}).then((res) => {
      _loading.close()
      if (res.status === 200) {
        this.dialogBox.width = '1000px'
        this.dialogBox.component = 'personal-user-show'
        this.$nextTick(() => {
          this.dialogBox.visible = true
          this.dialogBox.index = index
        })
      } else {
        errorMessage(res.message)
      }
    }).catch((err) => {
      _loading.close()
    })
  }


  /**
   * 对话框：查看简历
   *
   * @param {Number} id
   * @param {Number} index
   * @return {void}
   */
  public dialogResumeShow(id: number, index: number = -1): void {
    const _loading = loading({background: 'transparent'})
    this.resumeShow({id}).then((res) => {
      _loading.close()
      if (res.status === 200) {
        this.dialogBox.width = '1100px'
        this.dialogBox.component = 'resume-show'
        this.$nextTick(() => {
          this.dialogBox.visible = true
          this.dialogBox.index = index
        })
      } else {
        errorMessage(res.message)
      }
    }).catch((err) => {
      _loading.close()
    })
  }

  /**
   * 对话框：查看个人用户投递记录
   * @param uid
   * @param params
   */
  public dialogPersonalUserSend(uid: number, params: any = {}): void {
    const _loading = loading({background: 'transparent'})
    this.getPersonalUserSend({uid, params}).then((res) => {
      _loading.close()
      if (res.status === 200) {
        this.dialogBox.width = '1100px'
        this.dialogBox.component = 'personal-user-send'
        this.$nextTick(() => {
          this.dialogBox.visible = true
        })
      } else {
        errorMessage(res.message)
      }
    }).catch((err) => {
      _loading.close()
    })
  }

  /**
   * 对话框：简历投递单
   *
   * @param {Number} id
   * @param {object} [params]
   * @return {void}
   */
  public dialogPersonalResumeSend(id: number, params: any = {}): void {
    const _loading = loading({background: 'transparent'})
    this.getPersonalResumeSend({id, params}).then((res) => {
      _loading.close()
      if (res.status === 200) {
        this.dialogBox.width = '1100px'
        this.dialogBox.component = 'personal-resume-send'
        this.$nextTick(() => {
          this.dialogBox.visible = true
        })
      } else {
        errorMessage(res.message)
      }
    }).catch((err) => {
      _loading.close()
    })
  }

  /**
   * 对话框：个人用户收到面试
   *
   * @param {Number} uid
   * @param {Object} [params]
   * @return {void}
   */
  public dialogPersonalUserReceiveInterview(uid: number, params: any = {}): void {
    const _loading = loading({background: 'transparent'})
    this.getPersonalUserReceiveInterview({uid, params}).then((res) => {
      _loading.close()
      if (res.status === 200) {
        this.dialogBox.width = '1100px'
        this.dialogBox.component = 'personal-user-receive-interview'
        this.$nextTick(() => {
          this.dialogBox.visible = true
        })
      } else {
        errorMessage(res.message)
      }
    }).catch((err) => {
      _loading.close()
    })
  }

  /**
   * 对话框：简历投递单
   *
   * @param {Number} id
   * @param {Object} [params]
   * @return {void}
   */
  public dialogPersonalResumeReceiveInterview(id: number, params: any = {}): void {
    const _loading = loading({background: 'transparent'})
    this.getPersonalResumeReceiveInterview({id, params}).then((res) => {
      _loading.close()
      if (res.status === 200) {
        this.dialogBox.width = '1100px'
        this.dialogBox.component = 'personal-resume-receive-interview'
        this.$nextTick(() => {
          this.dialogBox.visible = true
        })
      } else {
        errorMessage(res.message)
      }
    }).catch((err) => {
      _loading.close()
    })
  }

  /**
   * 对话框：按个人查看登录记录
   *
   * @param {Number} uid
   * @param {Object} [params]
   * @return {void}
   */
  public dialogUserLoginRecord(uid: number, params: any = {}): void {
    const _loading = loading({background: 'transparent'})
    this.userLoginRecord({uid, params}).then((res) => {
      _loading.close()
      if (res.status === 200) {
        this.dialogBox.width = '900px'
        this.dialogBox.component = 'personal-user-login-record'
        this.$nextTick(() => {
          this.dialogBox.visible = true
        })
      } else {
        errorMessage(res.message)
      }
    }).catch((err) => {
      _loading.close()
    })
  }
}
